<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>


    <SCript>
        //声明了一段文字
        let str = "我是一段字符串文体"
        //声明一个数组
        let arr = [1, 'a', 'b', 'c', 'e']
        //length
        console.log('字符串长度' + str.length);
        console.log('数组长度' + arr.length);
        //通过索引（下标）获取元素值 从0开始
        console.log(str[1]); //是
        console.log(arr[3]); //c
        console.log(arr[arr.length - 1]);
        //字符串转换为数组
        let str2 = '我是一段,即将被,转换为,数组的,字符串'
        let res = str2.split(',')
        console.log(res);
        //JOIN 将数组转换为字符串
        let arr2 = ['王者荣耀','和平精英','元神']
        let res2 = arr2.join('*');
        console.log(res2);
        //unicoder码的转换S
        let uniStr = '王者荣耀'
        let uinNum = uniStr.charCodeAt(3)//将汉字转换成code码
        console.log(uniStr.charCodeAt());
        console.log(String.fromCharCode(uinNum));//将code码转回汉字
        //对象字符串
        let newStr = new String('abcd');
        console.log(newStr);
        //charAt()方法获取对应索引的值
        let str3 = 'abcd123'
        console.log(str3.charAt(3));//等同于str3[+       //indexof()、lastIndexOf()   如果能找到该元素 则返回元素的下标 如果找不到则返回-1
        let str4 = "心javascript是前端的核心语言"
        console.log(str4.indexOf('ac'));//从前面找
        console.log((str4.lastIndexOf('心心')));//从后面找
        let str5 = '546813651@qq.com'
        console.log(str5.lastIndexOf('qq.com'));
        //match()若存在则以数组形式对应元素，若找不到则返回null
        console.log(str5.match('qq.com'));
        //search()若找到返回元素下标，找不到返回-1
        console.log(str5.search('qq.com'));
        console.log(str5.endsWith('qq.com'));
        //字符串拼接合并concat()
        let str6 = '你好，'
        let str7 = '范先生'
        console.log(str6+str7);
        console.log(str6.concat(str7));
        //字符串截取.slice(1,5)n代表截取开始且包含n，m代表街区的结束
        let str8 = '我是一段可以呗截取的字符'
        console.log(str8.slice(1,5));
        let work = 'abcd王njln者njasd荣耀'
        console.log(work.slice(4,5));
        console.log(work.slice(9,10));
        console.log(work.slice(15,17));
        console.log(work.lastIndexOf('王'))
        console.log(work.lastIndexOf('者'))
        console.log(work.lastIndexOf('荣耀'))
        console.log(work[4]+work[9]+work[15]+work[16]);
        //去除字符串两端的空格
        let str9 = '    WE      B21-3班'
        console.log(str9.trim());
        //大小写转化-`toLowerCase`：转小写-`toUpperCase`：转大写
        let str10 = 'ahgisadogfABC'
        console.log(str10.toLowerCase());
        //字符替换,不会改变原数据
        let str11 = "我是范先生"
        console.log(str11.replace("范先生","陈女士"));
        //Base64编码-- **btoa()**将字符串或二进制值转为Base64编码**atob()**将Base64编码转为原来的编码
        let str12 = 'thsggfds'
        console.log(btoa(str12));
        //汉字转码
        let str13 = '我是汉字'
        let btoaStr = btoa(encodeURIComponent(str13))
        console.log(btoaStr);
        let atobStr = decodeURIComponent((str13))
        console.log(atobStr);


    </SCript>